import { PageData } from '@/types/resp.ts'
import request from '@/utils/request.ts'
import {
  Role,
  RoleMenu,
  RolePageParam,
  RoleRemoveParam,
  RoleSaveOrUpdateParam,
  RoleMenusParam,
  RoleMenusUpdateParam,
  RoleListParam,
} from '@/types'

/*分页查询接口*/
export const page = (param: RolePageParam): Promise<PageData<Role>> => {
  return request({
    url: '/role/page',
    method: 'post',
    data: param,
  })
}

/*删除接口*/
export const remove = (param: RoleRemoveParam): Promise<unknown> => {
  return request({
    url: '/role/remove',
    method: 'post',
    data: param,
  })
}

/*保存或更新接口*/
export const saveOrUpdate = (param: RoleSaveOrUpdateParam): Promise<Role> => {
  return request({
    url: '/role/saveOrUpdate',
    method: 'post',
    data: param,
  })
}

/*角色菜单查询接口*/
export const menus = (param: RoleMenusParam): Promise<RoleMenu> => {
  return request({
    url: '/role/menus',
    method: 'post',
    data: param,
  })
}

/*角色菜单更新接口*/
export const menusUpdate = (param: RoleMenusUpdateParam) => {
  return request({
    url: '/role/menus/update',
    method: 'post',
    data: param,
  })
}

export const list = (param: RoleListParam): Promise<Role[]> => {
  return request({
    url: '/role/list',
    method: 'post',
    data: param,
  })
}
